package io.renren.modules.message.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.modules.message.entity.ZxMessageEntity;
import io.renren.modules.message.service.ZxMessageService;
import io.renren.modules.sys.entity.SysUserEntity;
import io.renren.modules.sys.entity.SysUserTokenEntity;
import io.renren.modules.sys.service.SysUserTokenService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.web.servlet.Cookie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-11-26 15:33:30
 */
@RestController
@RequestMapping("message/zxmessage")
public class ZxMessageController {
    @Autowired
    private ZxMessageService zxMessageService;
    @Autowired
    private SysUserTokenService sysUserTokenService;
    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("message:zxmessage:list")
    public R list(@RequestParam Map<String, Object> params, HttpServletRequest request, HttpServletResponse response)throws Exception{
        PageUtils page = zxMessageService.queryPage(params);
        //获取登录用户信息
        SysUserEntity sysUserEntity=sysUserTokenService.getSysUserByToken(request);
        Long userId=sysUserEntity.getUserId();
        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("message:zxmessage:info")
    public R info(@PathVariable("id") Long id){
			ZxMessageEntity zxMessage = zxMessageService.selectById(id);

        return R.ok().put("zxMessage", zxMessage);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("message:zxmessage:save")
    public R save(@RequestBody ZxMessageEntity zxMessage){
			zxMessageService.insert(zxMessage);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("message:zxmessage:update")
    public R update(@RequestBody ZxMessageEntity zxMessage){
			zxMessageService.updateById(zxMessage);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("message:zxmessage:delete")
    public R delete(@RequestBody Long[] ids){
			zxMessageService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
